home *** CD-ROM | disk | FTP | other *** search
- #include "ToolSort.h"
-
- /*=========================================================================
- Module: GetValidSel
-
- Purpose: Get a Selection and verify if Selection is correct type,
- correct format.
-
- Returns: Valid-Selection
-
- Functional Details:
-
- Verify if Selection Type IS 'TEXT'
- Check if last character of Selection is eol
- Report errors to user
-
- =========================================================================*/
-
- GetValidSel(validSel)
- SelRec *validSel; /* Ptr to SelRec */
- {
- Handle scrap; /* Handle to scrap */
- Handle selection; /* Handle to scrap */
- int error = 0;
- long length; /* Scrap length */
-
- length = GetSel( &scrap );
- if ( length > 0 )
- {
- if ( (*scrap)[length-1] != '\r' )
- error += End_Error;
- else
- {
- HLock( scrap );
- error = PtrToHand(*scrap, &selection, length); /* copy scrap */
- HUnlock( scrap );
-
- if (error != noErr)
- error = Memory_Error;
- }
- }
- else
- error = -length; /* if length <0 then error */
-
- if ( error != No_Error )
- {
- validSel->sel = 0L; /* On error set handle to Nil */
- validSel->length = 0;
- }
- else
- {
- validSel->sel = selection;
- validSel->length = length;
- }
-
- return( error );
- }
-
- long GetSel( sel )
- Handle *sel; /* Ptr to a Handle to the scrap */
- {
- int err = noErr;
- long len; /* len of scrap */
-
- #if DESK_SCRAP /* Desk Scrap */
- {
- long offset; /* offset to start of data */
- ResType type = 'TEXT';
-
- *sel = NewHandle(0L); /* Allocate minimum space*/
- if (*sel == NIL) /* error check */
- err += Memory_Error;
- else
- {
- len = GetScrap( *sel, type, &offset);
-
- if ( len <= 0 )
- {
- switch( len )
- {
- case NULL:
- err += Empty_Error;
- break;
- case noTypeErr:
- err += Type_Error;
- break;
- case memFullErr:
- err += Memory_Error;
- break;
- default:
- if (len < 0)
- err += Sys_Error;
- }
- *sel = 0L; /* On error set handle to NIL */
- len = -err; /* if length <0 then error */
- }
- }
-
- return( len );
-
- }
-
- #else /* Text edit scrap */
-
- *sel = TEScrapHandle();
- len = TEGetScrapLen();
-
- if ( len <= 0)
- {
- err = Empty_Error;
- *sel = 0L; /* On error set handle to NIL */
- len = -err; /* if length <0 then error */
- }
-
- return( len );
-
- #endif
- }
-
-